using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Guest_XemChiTietSeminar : System.Web.UI.Page
{
    SeminarBUS sBus = new SeminarBUS();
    SeminarDTO sDto = new SeminarDTO();
    private int NUM_ROWS_PER_PAGE = 4;
    private int TRANG_HH = 1;
    private int TONG_DONG = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        int maSeminar = 0;
        try
        {
            maSeminar = int.Parse(Request["idSeminar"]);
        }catch(Exception ex)
        {
            Console.Write(ex.Message.ToString());
            Response.Redirect("~/Guest/Default.aspx");
        }
        sDto = sBus.getSeminarChiTiet(maSeminar);
        lbMaSeminar.Text = sDto.MaSeminar.ToString();
        tdVanDe.InnerHtml = sDto.VanDeTB;
        tdNoiDung.InnerHtml = sDto.TomTatNoiDung;
        lbTenGiaoVien.Text = sDto.TenGiaoVien;
        tdNhanXet.InnerHtml = sDto.NhanXet;
        lbNgaySeminar.Text = sDto.NgaySeminar.ToShortDateString();
        lbHuongNghienCuu.Text = sDto.TenHuongNC;
        if (sDto.TaiLieuDinhKem.Length == 0)
            hplTaiLieu.Visible = false;
        else
        {
            hplTaiLieu.Visible = true;
            hplTaiLieu.NavigateUrl = "~/TaiLieuDinhKem/" + sDto.TaiLieuDinhKem;
        }

       
        DataTable dt = sBus.getBangSeminarChiTietTheoMaHNC(-1,0,sDto.MaHuongNC);
        TONG_DONG = dt.Rows.Count;
        int kt = TONG_DONG % NUM_ROWS_PER_PAGE;
        int soDong = TONG_DONG / NUM_ROWS_PER_PAGE;
        if (kt != 0)
            soDong += 1;
        int TONG_TRANG = (int)(soDong);
        numberPaging.Text = TONG_TRANG.ToString();
        if (TONG_TRANG <= 1)
        {
            LinkButton1.Visible = false;
            LinkButton2.Visible = false;
        }
        LayDuLieu();
    }
    private void LayDuLieu()
    {
        SeminarBUS sBus = new SeminarBUS();
        DataTable dt = sBus.getBangSeminarChiTietTheoMaHNC((TRANG_HH - 1) * NUM_ROWS_PER_PAGE, NUM_ROWS_PER_PAGE,sDto.MaHuongNC);
        GridView1.DataSource = dt;
        GridView1.DataBind();
        pagingLabel.Text = TRANG_HH.ToString();
    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        TRANG_HH = int.Parse(pagingLabel.Text) + 1;
        LayDuLieu();
        if (TRANG_HH * NUM_ROWS_PER_PAGE >= TONG_DONG)
        {
            LinkButton2.Visible = false;
        }
        if (TRANG_HH != 1)
            LinkButton1.Visible = true;
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        TRANG_HH = int.Parse(pagingLabel.Text) - 1;
        if (TRANG_HH <= 1) TRANG_HH = 1;
        LayDuLieu();
        if (TRANG_HH == 1)
        {
            LinkButton1.Visible = false;
        }
        if (TRANG_HH * NUM_ROWS_PER_PAGE < TONG_DONG)
            LinkButton2.Visible = true;
    }



    protected void xemChiTietSeminar(object sender, EventArgs e)
    {
        LinkButton lb = (LinkButton)sender;
        if (lb.CommandName == "xemChiTietSeminar")
        {
            Response.Redirect("~/Guest/XemChiTietSeminar.aspx?idSeminar=" + lb.CommandArgument);
        }
    }
}
